package com.xhorse.lockplatform.comm.enums;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Think
 * @date 2017/10/27
 */
public enum ResultEnum {

    SUCCESS("1001", "SUCCESS"),
    FAILED("1002", "FAILURE"),

    // 登陆错误信息
    LOGIN_NO_ACCOUNT("100","账号不存在"),
    LOGIN_ACCOUNT_ERROR("101","账号或密码错误"),
    LOGIN_TIME_OUT("102","登陆超时"),
    LOGIN_SMS_ERROR("103","验证码错误"),
    LOGIN_ERROR("104","登陆异常"),
    // 注册错误信息
    REGISTER_MOBILE_EXIST("200","该手机号已被注册"),
    REGISTER_EMAIL_EXIST("201","该邮箱已被注册"),
    REGISTER_FORMAT_ERROR("202","手机号格式错误"),
    REGISTER_EMAIL_ERROR("203","邮箱格式错误"),
    REGISTER_PASSWORD_ERROR("204","密码格式错误"),
    REGISTER_PASSWORD_MATCH("205","密码不符"),
    REGISTER_ERROR_RETRY("206","注册异常，请重试"),
    REGISTER_INFO_EMPTY("207","所填信息不能为空"),
    REGISTER_REQUIRED_NOT_COMPLETED("208","必填选项未完成"),
    REGISTER_REPEATED_ACTIVATION("209","请勿重复激活"),
    REGISTER_AUTHENTICATION_ERROR("210","身份认证失败，请重试"),
    REGISTER_SEND_ERROR("211","短信发送失败，请重新发送"),
    REGISTER_SMS_MATCH("212","验证码不匹配，请重试"),
    REGISTER_ERROR("213","注册失败"),
    REGISTER_USERNAME_ERROR("214","用户名不符合规定格式"),
    REGISTER_SMS_SEND_ERROR("215","验证码发送失败，请重试"),
    // 查询错误信息
    CRUD_INFO_EMPTY("300","信息不能为空"),
    CRUD_TIME_OUT("301","查询超时"),
    CRUD_QUERY_INFO_ERROR("302","查询条件错误"),
    CRUD_QUERY_INFO_MATCH("303","查询字段数据不匹配"),
    CRUD_ADD_ERROR("304","数据添加失败"),
    CRUD_UPDATE_ERROR("305","更新失败"),
    CRUD_DELETE_ERROR("306","删除失败"),
    CRUD_RESULT_ERROR("308","结果为空"),
    CRUD_NEW_VERSION("309","数据库已是最新版本"),
    CRUD_NOT_FILE("310","文件不存在"),
    CRUD_UNSUPPORTED_LANGUAGE("311","该地区不支持此种语言"),
    CRUD_NOT_DATA("312","暂无数据"),
    CRUD_REPEATED_COMMIT("313","请勿重复提交"),
    //添加设备模块错误信息
    EQUIPMENT_OCCUPANCY("400","这台设备已被占用"),
    EQUIPMENT_CODE_OR_NUMBER_ERROR("402","激活码或序列号错误，请重试"),
    EQUIPMENT_SERIALNUMBER_ERROR("405","序列号错误，请重试"),
    EQUIPMENT_REPEATED_ERROR("403","不能重复添加"),
    EQUIPMENT_INFO_ERROR("404","信息栏错误，请重试"),
    EQUIPMENT_PRODUCT_SHIP("307","该产品已经发货"),

    NETWORK_ERROR("500","请求失败，请重试"),

    SYSTEM_UNKNOWN("-1", "未知错误"),
    SYSTEM_NOT_FOUND("9999", "没有对应数据信息");


    private final String code;
    private final String msg;

    ResultEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 通过枚举code获取对应的msg
     *
     * @return 取不到时返回null
     */
    public static String getMsgByCode(String code) {
        for (ResultEnum _enum : values()) {
            if (_enum.getCode().equals(code)) {
                return _enum.getMsg();
            }
        }
        return null;
    }

    /**
     * 通过枚举code获取枚举对象
     *
     * @return 取不到时返回null
     */
    public static ResultEnum getByCode(String code) {
        for (ResultEnum _enum : values()) {
            if (_enum.getCode().equals(code)) {
                return _enum;
            }
        }
        return null;
    }

    /**
     * 获取全部枚举
     *
     * @return 取不到时返回空List=new ArrayList<>()
     */
    public List<ResultEnum> getAllEnum() {
        List<ResultEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 获取全部枚举code
     *
     * @return 取不到时返回空List=new ArrayList<Integer>()
     */
    public List<String> getAllEnumCode() {
        List<String> list = new ArrayList<>();
        for (ResultEnum _enum : values()) {
            list.add(_enum.getCode());
        }
        return list;
    }

}
